<template>
    <div class="body-box">
        <div class="login-box">
            <div class="box-left">
                <img class="login-bg" src="@/assets/img/login/login.png">
            </div>
            <div class="box-right">
                <p class="title">登录</p>
                <input type="text" class="user" placeholder="请输入登录邮箱" v-model="name">
                <input type="password" class="pwd" placeholder="请输入密码" v-model="pwd">
                <div class="flex flex-align-center check-box">
                    <CheckBox :is_show='is_remember' v-on:change="onChange"/>
                    <div class="label">记住我</div>
                </div>
                <div class="button-box flex flex-align-center flex-pack-center" @click="onSubmit">
                    <p>登录</p>
                </div>
                <div class="info-box">
                    <p class="info" v-if='info'>暂无相关权限，请联系管理员</p>
                </div>
                <p class="foot-tips">若忘记密码，请联系管理员修改密码</p>
            </div>
        </div>
    </div>
</template>
<script>
import CheckBox from "../components/common/checkbox";
export default {
  components: {
    CheckBox
  },
  data () {
      return {
        name:'',
        pwd:'',
        info:false,
        is_remember:false
      }
  },
  mounted () {
      this.onRemember();
  },
  methods: {

    //   是否勾选记住密码
      onChange(){
          this.is_remember = !this.is_remember
      },

    //   登录
    async onSubmit(){
        if(!this.name || !this.pwd){
            return;
        }
        var params = {
            userMail:this.name,
            userPass:this.pwd
        }
        var {data} = await this.$https.post('member/login',params);
        if(data){
            sessionStorage.token = data.token;
            sessionStorage.uid = data.uid;
            if(this.is_remember){ // 如果用户勾选记住密码
                localStorage.netdisk_user = this.name;
                localStorage.netdisk_pwd = this.pwd;
            }else{
                localStorage.netdisk_user = '';
                localStorage.netdisk_pwd = '';
            }
            this.$router.push('/layout');
        }
    },

    // 检测是否记住密码
    onRemember(){
        if(localStorage.netdisk_user && localStorage.netdisk_pwd){
            this.is_remember = true;
            this.name = localStorage.netdisk_user;
            this.pwd = localStorage.netdisk_pwd;
        }
    }
  }
}
</script>
<style lang="less" scoped>
@import url(../assets/css/login/login.less);
</style>


